import Vue from "vue";
import Router from "vue-router";

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router);

/* Layout */
import Layout from "../views/layout/Layout";

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [{
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },
  {
    path: "/register",
    component: () => import("@/views/register/index"),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    name: "Dashboard",
    hidden: true,
    children: [{
      path: "dashboard",
      component: () => import("@/views/dashboard/index")
    }]
  },
];

export default new Router({
   mode: 'hash', //后端支持可开
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRouterMap
});

export const asyncRouterMap = [{
    path: "/customers",
    component: Layout,
    hidden: true,
    redirect: "/customers",
    meta: {
      roles: ['admin']
    },
    children: [{
        path: "/customers",
        name: "customerlist",
        hidden: true,
        component: () => import("@/views/customers/customer"),
        meta: {
          roles: ['admin'],
          title: "客户管理"
        }
      },
      {
        path: "/customers",
        component: () => import("@/views/layout/components/AppMain"),
        hidden: true,
        name: "customerMemberList",
        meta: {
          roles: ['admin'],
          title: "客户管理"
        },
        children: [{
          path: "customerMember/:id",
          name: "customerMemberListId",
          hidden: true,
          component: () => import("@/views/customers/customerMember"),
          meta: {
            roles: ['admin'],
            title: "成员管理"
          }
        }]
      }
    ]
  },
  {
    path: "/devices",
    component: Layout,
    redirect: "/devices",
    meta: {
      roles: ['admin']
    },
    children: [{
        path: "",
        name: "Devices",
        component: () => import("@/views/devices/index"),
        meta: {
          roles: ['admin'],
          title: "设备管理",
          icon: "device"
        }
      },
      {
        path: "/devices",
        hidden: true,
        component: () => import("@/views/layout/components/AppMain"),
        name: "DeviceTypes",
        meta: {
          roles: ['admin'],
          title: "设备管理"
        },
        children: [{
            path: "/devices/incubatorList",
            name: "incubatorList",
            hidden: true,
            component: () => import("@/views/devices/incubatorList"),
            meta: {
              roles: ['admin'],
              title: "保温箱"
            }
          },
          {
            path: "/devices/carList",
            name: "carList",
            hidden: true,
            component: () => import("@/views/devices/carList"),
            meta: {
              roles: ['admin'],
              title: "冷藏车"
            }
          },
          {
            path: "/devices/warehouseList",
            name: "warehouseList",
            hidden: true,
            component: () => import("@/views/devices/warehouseList"),
            meta: {
              roles: ['admin'],
              title: "库房"
            }
          },
          {
            path: "/devices/incubatorEdit/:id(\\d+)",
            name: "incubatorEdit",
            hidden: true,
            component: () => import("@/views/devices/incubatorEdit"),
            meta: {
              roles: ['admin'],
              title: "保温箱编辑"
            }
          },
          {
            path: "/devices/incubatorAdd",
            name: "incubatorAdd",
            hidden: true,
            component: () => import("@/views/devices/incubatorAdd"),
            meta: {
              roles: ['admin'],
              title: "保温箱新增"
            }
          },
          {
            path: "/devices/carEdit/:id(\\d+)",
            name: "carEdit",
            hidden: true,
            component: () => import("@/views/devices/carEdit"),
            meta: {
              roles: ['admin'],
              title: "冷藏车编辑"
            }
          },
          {
            path: "/devices/carAdd",
            name: "carAdd",
            hidden: true,
            component: () => import("@/views/devices/carAdd"),
            meta: {
              roles: ['admin'],
              title: "冷藏车新增"
            }
          },
        ]
      }
    ]
  },
  {
    path: "/validate",
    component: Layout,
    redirect: "/validate",
    meta: {
      roles: ['admin']
    },
    children: [{
        path: "",
        name: "Validate",
        component: () => import("@/views/validate/index"),
        meta: {
          roles: ['admin'],
          title: "验证配置",
          icon: "validate"
        }
      },
      {
        path: "/validate",
        name: "ValidateTypes",
        hidden: true,
        component: () => import("@/views/layout/components/AppMain"),
        meta: {
          roles: ['admin'],
          title: "验证配置"
        },
        children: [{
            path: "/validate/carList",
            component: () => import("@/views/layout/components/AppMain"),
            redirect: "/validate/carList",
            children: [{
                path: "/validate/incubatorList",
                component: () => import("@/views/layout/components/AppMain"),
                redirect: "/validate/incubatorList",
                children: [{
                    path: '',
                    name: "incubatorValidate",
                    component: () => import("@/views/validate/incubatorList"),
                    meta: {
                      roles: ['admin'],
                      title: "保温箱编辑"
                    }
                  },
                  {
                    path: "/validate/incubatorList",
                    hidden: true,
                    component: () => import("@/views/layout/components/AppMain"),
                    name: "incubatorValidateType",
                    meta: {
                      roles: ['admin'],
                      title: "保温箱编辑"
                    },
                    children: [{
                        path: "/validate/incubator/distributionTemp",
                        name: "incubatorDistributionTemplate",
                        hidden: true,
                        component: () => import("@/views/validate/incubator/distributionTemp"),
                        meta: {
                          roles: ['admin'],
                          title: "布点方式"
                        }
                      },
                      {
                        path: "/validate/incubator/textTemp",
                        name: "incubatorTextTemplate",
                        hidden: true,
                        component: () => import("@/views/validate/incubator/textTemp"),
                        meta: {
                          roles: ['admin'],
                          title: "文字模板"
                        }
                      },
                      {
                        path: "/validate/incubator/picTemp",
                        name: "incubatorPicTemplate",
                        hidden: true,
                        component: () => import("@/views/validate/incubator/picTemp"),
                        meta: {
                          roles: ['admin'],
                          title: "图片模板"
                        }
                      },
                      {
                        path: "/validate/incubator/fanganTemp",
                        name: "incubatorFanganTemplate",
                        hidden: true,
                        component: () => import("@/views/validate/incubator/fanganTemp"),
                        meta: {
                          roles: ['admin'],
                          title: "方案模板"
                        }
                      },
                      {
                        path: "/validate/incubator/reportTemp",
                        name: "incubatorRaogaoTemplate",
                        hidden: true,
                        component: () => import("@/views/validate/incubator/reportTemp"),
                        meta: {
                          roles: ['admin'],
                          title: "报告模板"
                        }
                      }
                    ]
                  }
                ]
              },
              {
                path: '',
                name: "carrValidate",
                component: () => import("@/views/validate/carList"),
                meta: {
                  roles: ['admin'],
                  title: "冷藏车编辑"
                }
              },
              {
                path: "/validate/carList",
                hidden: true,
                component: () => import("@/views/layout/components/AppMain"),
                name: "carValidateType",
                meta: {
                  roles: ['admin'],
                  title: "冷藏车编辑"
                },
                children: [{
                  path: "/validate/car/distributionTemp",
                  component: () => import("@/views/layout/components/AppMain"),
                  redirect: "/validate/car/distributionTemp",
                  children:[{
                      path: "/validate/car/distributionTemp",
                      name: "carDistributionTemplate",
                      hidden: true,
                      component: () => import("@/views/validate/car/distributionTemp"),
                      meta: {
                        roles: ['admin'],
                        title: "布点方式"
                      }
                    },
                    {
                      path: "",
                      hidden: true,
                      component: () => import("@/views/layout/components/AppMain"),
                      meta: {
                        roles: ['admin'],
                        title: "布点方式"
                      },
                      children:[
                        {
                          path: "/validate/car/distributionTempEdit/:id(\\d+)",
                          name: "carDistributionTempEdit",
                          hidden: true,
                          component: () => import("@/views/validate/car/distributionTempEdit"),
                          meta: {
                            roles: ['admin'],
                            title: "布点方式编辑"
                          }
                        },
                      ]
                    }
                  ]
                    
                  },

                  {
                    path: "/validate/car/textTemp",
                    name: "carTextTemplate",
                    hidden: true,
                    component: () => import("@/views/validate/car/textTemp"),
                    meta: {
                      roles: ['admin'],
                      title: "文字模板"
                    }
                  },
                  {
                    path: "/validate/car/picTemp",
                    name: "carPicTemplate",
                    hidden: true,
                    component: () => import("@/views/validate/car/picTemp"),
                    meta: {
                      roles: ['admin'],
                      title: "图片模板"
                    }
                  },
                  {
                    path: "/validate/car/fanganTemp",
                    name: "carFanganTemplate",
                    hidden: true,
                    component: () => import("@/views/validate/car/fanganTemp"),
                    meta: {
                      roles: ['admin'],
                      title: "方案模板"
                    }
                  },
                  {
                    path: "/validate/car/reportTemp",
                    name: "carReportTemplate",
                    hidden: true,
                    component: () => import("@/views/validate/car/reportTemp"),
                    meta: {
                      roles: ['admin'],
                      title: "报告模板"
                    }
                  }
                ]
              }
            ]
          },
          {
            path: "/validate/warehouseList",
            component: () => import("@/views/layout/components/AppMain"),
            redirect: "/validate/warehouseList",
            children: [{
                path: '',
                name: "warehouseValidate",
                component: () => import("@/views/validate/warehouseList"),
                meta: {
                  title: "库房编辑"
                }
              },
              {
                path: "/validate/warehouseList",
                hidden: true,
                component: () => import("@/views/layout/components/AppMain"),
                name: "warehouseValidateType",
                meta: {
                  title: "库房编辑"
                },
                children: [{
                    path: "/validate/warehouse/distributionTemp",
                    name: "warehouseDistributionTemplate",
                    hidden: true,
                    component: () => import("@/views/validate/warehouse/distributionTemp"),
                    meta: {
                      title: "布点方式"
                    }
                  },
                  {
                    path: "/validate/warehouseList/textTemp",
                    name: "warehouseTextTemplate",
                    hidden: true,
                    component: () => import("@/views/validate/warehouse/textTemp"),
                    meta: {
                      title: "文字模板"
                    }
                  },
                  {
                    path: "/validate/warehouseList/picTemp",
                    name: "warehousePicTemplate",
                    hidden: true,
                    component: () => import("@/views/validate/warehouse/picTemp"),
                    meta: {
                      title: "图片模板"
                    }
                  },
                  {
                    path: "/validate/warehouseList/fanganTemp",
                    name: "warehouseFanganTemplate",
                    hidden: true,
                    component: () => import("@/views/validate/warehouse/fanganTemp"),
                    meta: {
                      title: "方案模板"
                    }
                  },
                  {
                    path: "/validate/warehouseList/reportTemp",
                    name: "warehouseReportTemplate",
                    hidden: true,
                    component: () => import("@/views/validate/warehouse/reportTemp"),
                    meta: {
                      title: "报告模板"
                    }
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  {
    path: "/charts",
    component: Layout,
    meta: {
      roles: ['admin']
    },
    children: [{
      path: "index",
      name: "Charts",
      component: () => import("@/views/charts/index"),
      meta: {
        roles: ['admin'],
        title: "总数据表",
        icon: "chart"
      }
    }]
  },

  {
    path: "/projectsClass",
    component: Layout,
    meta: {
      roles: ['admin']
    },
    children: [{
      path: "index",
      name: "ProjectsClass",
      component: () => import("@/views/projectsClass/index"),
      meta: {
        roles: ['admin'],
        title: "项目类别配置",
        icon: "class"
      }
    }]
  },
  {
    path: "/users",
    component: Layout,
    name: "用户管理",
    meta: {
      roles: ['admin']
    },
    children: [{
      path: "index",
      name: "Users",
      component: () => import("@/views/users/index"),
      meta: {
        roles: ['admin'],
        title: "用户管理",
        icon: "user"
      }
    }]
  },

  {
    path: "/task",
    component: Layout,
    redirect: "/task",
    children: [{
        path: '',
        name: "Tasks",
        component: () => import("@/views/tasks/index"),
        meta: {
          roles: ['manager','engineer'],
          title: "任务列表",
          icon: "order"
        }
      },
      {
        path: "/task",
        hidden: true,
        component: () => import("@/views/layout/components/AppMain"),
        name: "TasksList",
        meta: {
          roles:  ['manager','engineer'],
          title: "任务列表",
        },
        children: [{
            path: "/task/project/:id(\\d+)",
            component: () => import("@/views/layout/components/AppMain"),
            redirect: "/task/project/:id(\\d+)",
            children: [{
              path: '',
              name: "Projects",
              component: () => import("@/views/tasks/projects/index"),
              meta: {
                roles: ['manager','engineer'],
                title: "子项目列表"
              }
            },
            {
              path: '/task/project/:id(\\d+)',
              name: "ProjectsList",
              component: () => import("@/views/layout/components/AppMain"),
              meta: {
                roles: ['manager','engineer'],
                title: "子项目列表"
              },
              children: [
                {
                  path: "/task/project/progress/:id(\\d+)",
                  name: "ProjectProgress",
                  hidden: true,
                  component: () => import("@/views/tasks/projects/progress/index"),
                  meta: {
                    roles: ['manager','engineer'],
                    title: "项目进度"
                  }
                },
                {
                  path: "/task/project/progress/participants/:id(\\d+)",
                  name: "ProjectParticipants",
                  hidden: true,
                  component: () => import("@/views/tasks/projects/progress/participants/index"),
                  meta: {
                    roles: ['manager','engineer'],
                    title: "验证参与人员"
                  }
                },
                {
                  path: "/task/project/track/:id(\\d+)",
                  name: "ProjectTrack",
                  hidden: true,
                  component: () => import("@/views/tasks/projects/track/index"),
                  meta: {
                    roles: ['manager','engineer'],
                    title: "项目跟踪"
                  }
                }
              ]
            }]
          },
          {
            path: "/task/track/:id(\\d+)",
            name: "track",
            hidden: true,
            component: () => import("@/views/tasks/track/index"),
            meta: {
              roles: ['manager','engineer'],
              title: "项目跟踪"
            }
          }
        ]
      }
    ]
  },

  // {
  //   path: "/project",
  //   component: Layout,
  //   meta: {
  //     roles: ['engineer']
  //   },
  //   children: [{
  //     path: "index",
  //     name: "工程师任务列表",
  //     component: () => import("@/views/tasks/projects/index"),
  //     meta: {
  //       roles: ['engineer'],
  //       title: "工程师任务列表",
  //       icon: "user"
  //     }
  //   }]
  // },
  {
    path: "/Gprojects",
    component: Layout,
    meta: {
      roles: ['guest']
    },
    children: [{
      path: "index",
      name: "客户任务列表",
      component: () => import("@/views/Gprojects/index"),
      meta: {
        roles: ['guest'],
        title: "客户任务列表",
        icon: "user"
      }
    }]
  },


  {
    path: "*",
    redirect: "/404",
    hidden: true
  }
]
